//
//  HXUserDetailsViewController.m
//  KD
//
//  Created by ifly on 16/3/16.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXUserDetailsViewController.h"
#import "HXSelectedViewController.h"
#import "HXSelectedAreaMapViewController.h"
#import "HXTabBarViewController.h"

@interface HXUserDetailsViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneNumberLabel;
@property (weak, nonatomic) IBOutlet UILabel *corpDepLabel;
@property (weak, nonatomic) IBOutlet UIView *hengxianView;
@property (weak, nonatomic) IBOutlet UILabel *corpKindNameLabel;
@property (weak, nonatomic) IBOutlet UIView *companyView;
@property (weak, nonatomic) IBOutlet UIView *stationView;
@property (weak, nonatomic) IBOutlet UIView *areaView;
@property (weak, nonatomic) IBOutlet UIView *organizationView;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *stationLabel;
@property (weak, nonatomic) IBOutlet UILabel *areaLabel;
@property (weak, nonatomic) IBOutlet UILabel *organizationLabel;



@end

@implementation HXUserDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    if ([[UserDefaultHandler getUserDetault:kUsers_Kind] integerValue] == UserTypeManage) {
        [self setUpMessage];
        self.companyView.hidden = YES;
        self.stationView.hidden = YES;
        self.areaView.hidden = YES;
        self.organizationView.hidden = YES;
    }
    else {
        [self setUpBusinessMessage];
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.parentViewController.tabBarController.tabBar.hidden = YES;
}

-(void)setUpMessage{
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_PersonName]]) {
        self.nameLabel.text = [UserDefaultHandler getUserDetault:kUsers_PersonName];
    }else{
        self.nameLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_CellPhoneNum]]) {
        self.phoneNumberLabel.text = [UserDefaultHandler getUserDetault:kUsers_CellPhoneNum];
    }else{
        self.phoneNumberLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_CorpName]]) {
        self.corpKindNameLabel.text = @"部门";
        self.corpDepLabel.text = [UserDefaultHandler getUserDetault:kUsers_CorpName];
    }else{
        self.corpDepLabel.text = @"暂无";
    }
}

-(void)setUpBusinessMessage {
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_PersonName]]) {
        self.nameLabel.text = [UserDefaultHandler getUserDetault:kUsers_PersonName];
    }else{
        self.nameLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_CellPhoneNum]]) {
        self.phoneNumberLabel.text = [UserDefaultHandler getUserDetault:kUsers_CellPhoneNum];
    }else{
        self.phoneNumberLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_CorpKindName]]) {
        self.corpKindNameLabel.text = @"企业类型";
        self.corpDepLabel.text = [UserDefaultHandler getUserDetault:kUsers_CorpKindName];
    }else{
        self.corpDepLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_CorpName]]) {
        self.companyLabel.text = [UserDefaultHandler getUserDetault:kUsers_CorpName];
    }else{
        self.companyLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_JobName]]) {
        self.stationLabel.text = [UserDefaultHandler getUserDetault:kUsers_JobName];
    }else{
        self.stationLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_AreaName]]) {
        self.areaLabel.text = [UserDefaultHandler getUserDetault:kUsers_AreaName];
    }else{
        self.areaLabel.text = @"暂无";
    }
    if (![GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kUsers_Organization]]) {
        self.organizationLabel.text = [UserDefaultHandler getUserDetault:kUsers_Organization];
    }else{
        self.organizationLabel.text = @"暂无";
    }
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (IBAction)outBtnClick:(id)sender {
    NSString *str = [UserDefaultHandler getUserDetault:kUsers_CellPhoneNum];
    [UserDefaultHandler initUserDefault];
    [UserDefaultHandler saveUserDetault:str key:kUsers_CellPhoneNum];
    UIWindow *win = [[UIApplication sharedApplication].delegate window];
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"HXLoginRegister" bundle:nil];
    HXSelectedViewController *hxSelectedVC = [storyBoard instantiateViewControllerWithIdentifier:@"HXSelectedViewController"];
    win.rootViewController = hxSelectedVC;
    [win makeKeyAndVisible];
    /**退出极光登录*/
    [JMSGUser logout:^(id resultObject, NSError *error) {
        if (error == nil) {
            DDLogDebug(@"Action logout success");
        }
    }];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kuserName];
}

@end
